home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library / Microsoft Programmer's Library (CD-ROM Database)(125-099-008)(Version 1.1a)(CDRM 162100)(1989).iso / SAMPCODE / ADVOS2 / CH05 / MOUDEMO.C
Text File  |  1988-12-12  |  2KB  |  71 lines

  1. /*
  2.     MOUDEMO.C   Simple demo of the OS/2 mouse API.
  3.     Copyright (C) 1988 Ray Duncan
  4.  
  5.     Compile with:  C> cl moudemo.c
  6.  
  7.     Usage is:  C> moudemo
  8. */
  9.  
  10. #include <stdio.h>
  11.  
  12. #define API unsigned extern far pascal
  13.  
  14. API MouReadEventQue(void far *, unsigned far *, unsigned);
  15. API MouOpen(void far *, unsigned far *);
  16. API MouClose(unsigned);
  17. API MouDrawPtr(unsigned);
  18. API VioScrollUp(unsigned, unsigned, unsigned, unsigned, 
  19.                 unsigned, char far *, unsigned);
  20. API VioWrtCharStr(void far *, unsigned, unsigned, unsigned, unsigned);
  21.  
  22. struct _MouEventInfo {  unsigned Flags;
  23.                         unsigned long Timestamp;
  24.                         unsigned Row;
  25.                         unsigned Col;
  26.                      }  MouEvent ;
  27.  
  28. main(int argc, char *argv[])
  29. {
  30.     char OutStr[40];                    /* for output formatting */ 
  31.     
  32.     unsigned Cell = 0x0720;             /* ASCII space and
  33.                                            normal attribute */
  34.  
  35.     unsigned MouHandle;                 /* mouse logical handle */
  36.     unsigned Status;                    /* returned from API */
  37.     int WaitOption = 1;                 /* 1 = block for event,
  38.                                            0 = do not block */
  39.  
  40.     Status = MouOpen(0L, &MouHandle);   /* open mouse device */
  41.  
  42.     if(Status)                          /* exit if no mouse */
  43.     {   
  44.         printf("\nMouOpen failed.\n");
  45.         exit(1);
  46.     }
  47.                                         /* clear the screen */  
  48.     VioScrollUp(0, 0, -1, -1, -1, &(char)Cell, 0);
  49.  
  50.     puts("Press Both Mouse Buttons To Exit");
  51.  
  52.     MouDrawPtr(MouHandle);              /* display mouse cursor */
  53.  
  54.     do                                  
  55.     {                                   /* format mouse position */    
  56.         sprintf(OutStr, "X=%2d Y=%2d", MouEvent.Col, MouEvent.Row);
  57.  
  58.                                         /* display mouse position */
  59.         VioWrtCharStr(OutStr, strlen(OutStr), 0, 0, 0);
  60.  
  61.                                         /* wait for a mouse event */
  62.         MouReadEventQue(&MouEvent, &WaitOption, MouHandle);
  63.         
  64.                                         /* exit if both buttons down */
  65.     } while((MouEvent.Flags & 0x14) != 0x14) ;
  66.  
  67.     MouClose(MouHandle);                /* release mouse handle */
  68.  
  69.     puts("Have a Mice Day!");           /* hail & farewell */
  70. }
  71.